package com.itheima.day01_springboot_init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Value("${name}")
    private String name;
    @Value("${person.name}")
    private String name2;
    @Value("${person.age}")
    private int age;
    @Value("${address[0]}")
    private String address1;
    @Value("${msg1}")
    private String msg1;
    @Value("${msg2}")
    private String msg2;

    @Autowired
    private Environment environment;  //注入一个环境对象,相当于可以批量注入多个@Value

    @RequestMapping("/hello2")
    public String hello2(){
        System.out.println(name);
        System.out.println(name2);
        System.out.println(age);
        System.out.println(address1);
        System.out.println(msg1);
        System.out.println(msg2);
        System.out.println("------------");
        System.out.println(environment.getProperty("person.name"));
        System.out.println(environment.getProperty("address[0]"));

        return "Hello SpringBoot2";
    }

    @RequestMapping("/hello")
    public String hello(){
        return "Hello SpringBoot2";
    }
}
